package cz.myslivec.slovicka.dao;

import java.io.Serializable;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.log.Log;

import cz.myslivec.slovicka.entity.VocableType;

@Name("vocableTypeDao")
@AutoCreate
public class VocableTypeDao implements Serializable {
	private static final long serialVersionUID = 12720444079847862L;

	@Logger
	Log log;

	@In
	private EntityManager entityManager;
	
	public VocableType get(String code) {
		if(code == null) {
			return null;
		}
		return entityManager.find(VocableType.class, code);
	}
	
	@Factory("vocableTypeList")
	@SuppressWarnings("unchecked")
	public List<VocableType> list() {
		Query query = entityManager.createQuery("from VocableType");
		return query.getResultList();
	}
}
